function login1() {
    //获取用户输入的用户和密码，通过Ajax发送给服务器
    let account = $("#account").val();

    let password = $("#password").val();

    let code = $("#code").val();

    $.ajax("adminUser/login", {
        type: "POST",
        data: {
            account: account,
            password: password,
            code:code
        },
        success: function(data, textStatus) {
			
			console.log(data)
            let datas = JSON.parse(data);
			
				// console.log(datas)
            if (datas.statusCode == 200) {
                let user = JSON.stringify(datas.datas.user);

                sessionStorage.setItem("user", user);

                alert(datas.errMsg);
				
				
				location.href="href?to="+datas.location;
               


            } else {
                alert(datas.errMsg)
            }
        }
    })

}


function getMealList(){
	
	return new Promise(function(resolve, reject) {
		$.ajax("Meal/getMealList", {
			type: "POST",
			data: {
				
			},
			success: function(data, textStatus) {
				console.log(data)
				let datas = JSON.parse(data);
				console.log(datas)
				if (datas.statusCode == 200) {
					resolve(datas.datas.list);
				} else {
					reject(datas.errMsg);
				}
			}
		})
	})
	
}
function getOrderList(page){
	let sdate = $("#sdate").val();
	let edate = $("#edate").val();
	let sname = $("#sname").val();
	let scardid = $("#scardid").val();
	let smeal = $("#smeal").val();
	if(sdate != '' && edate !=''){
		sdate = (new Date(sdate)).getTime()/1000;
		edate = (new Date(edate)).getTime()/1000;
		if(sdate == edate){
			alert("起始和结束时间不能为同一天");
			return;
		}else if(edate < sdate){
			alert("结束时间不能小于起始时间");
			return;
		}
	}

 	return new Promise(function(resolve, reject) {
		$.ajax("Order/getOrderList", {
			type: "POST",
			data: {
				sdate:sdate,
				edate:edate,
				sname:sname,
				scardid:scardid,
				smeal:smeal,
				page:page,
			},
			success: function(data, textStatus) {
				let datas = JSON.parse(data);
				if (datas.statusCode == 200) {
					resolve(datas.datas.order);
				} else {
					reject(datas.errMsg);
				}
			}
		})
	})
	
}


function addOrder(){
	
	
	let realname = $("#realname").val();
	
	let cardId = $("#cardId").val();
	
	let mealId = $("#meal_list").val();
	let phone = $("#phone").val();
	let sex = $("#sex").val();
	
	
	$.ajax("Order/addOrder", {
	    type: "POST",
	    data: {
	      realname:realname,
	      cardId:cardId,
	      mealId:mealId,
		  phone:phone,
		  sex:sex,
	    },
	    success: function(data, textStatus) {
			let datas = JSON.parse(data);
	        if (datas.statusCode == 200) {
	          
	
	            alert(datas.errMsg);
				
				location.href="href?to=meal_list&card_id="+cardId;	
				
				// location.reload();
	
	
	        } else {
	            alert(datas.errMsg)
	        }
	    }
	})
	
	
	
	
	
}



function getOrderInfo(id){
	return new Promise(function(resolve, reject) {
		$.ajax("Order/getOrderInfo", {
			type: "POST",
			data: {
				id:id,
				
			},
			success: function(data, textStatus) {
				let datas = JSON.parse(data);
				if (datas.statusCode == 200) {
					resolve(datas.datas.order);
				} else {
					reject(datas.errMsg);
				}
			}
		})
	})
}



function updateReportInfo(id){
	return new Promise(function(resolve, reject) {
		$.ajax("Order/getOrderInfo", {
			type: "POST",
			data: {
				id:id,
				
			},
			success: function(data, textStatus) {
				let datas = JSON.parse(data);
				if (datas.statusCode == 200) {
					resolve(datas.datas.order);
				} else {
					reject(datas.errMsg);
				}
			}
		})
	})
}

